using System;
using System.Data;
using System.Data.SqlClient;

namespace Company.BLL.KDT.GC
{
	public partial class ToKhaiChuyenTiep : EntityBase
	{
		#region Private members.
		
		protected long _ID;
		protected long _SoTiepNhan;
		protected DateTime _NgayTiepNhan = new DateTime(1900, 01, 01);
        protected int _TrangThai;
		protected string _MaHQ = String.Empty;
		protected int _ToKhaiSo;
		protected string _CanBoDangKy = String.Empty;
		protected DateTime _NgayDangKy = new DateTime(1900, 01, 01);
		protected string _SoHopDongNhan = String.Empty;
        protected string _MaNguoiNhan = String.Empty;
        protected string _TenNguoiNhan= String.Empty;
		protected DateTime _NgayHDNhan = new DateTime(1900, 01, 01);
		protected DateTime _NgayHetHanHDNhan = new DateTime(1900, 01, 01);
		protected string _MaNguoiGiao = String.Empty;
        protected string _TenNguoiGiao = String.Empty;
        protected string _SoHDGiao = String.Empty;
        protected DateTime _NgayHDGiao= new DateTime(1900, 01, 01);
        protected DateTime _NgayHetHanHDGiao = new DateTime(1900, 01, 01);
        protected string _NguoiChiDinhGiaoHang = String.Empty;
        protected string _MaDaiLy = String.Empty;
        protected string _TenDaiLy = String.Empty;
        protected string _MaLoaiHinh = string.Empty;
        protected string _TenLoaiHinh = string.Empty;
        protected string _DiaDiemXepHang = string.Empty;
        protected decimal _TyGiaVND;
        protected decimal _TyGiaUSD;
        protected decimal _LePhiHQ;
        protected string _SoBienLai = string.Empty;
        protected DateTime _NgayBienLai = new DateTime(1900, 01, 01);
        protected string _ChungTu = string.Empty;
        protected string _MaNguyenTe= string.Empty;
		#endregion 
		
		//---------------------------------------------------------------------------------------------

		#region Properties.
		
		public long ID
		{
			set {this._ID = value;}
			get {return this._ID;}
		}
        public int ToKhaiSo
        {
            set { this._ToKhaiSo = value; }
            get { return this._ToKhaiSo; }
        }
		public long SoTiepNhan
		{
			set {this._SoTiepNhan = value;}
			get {return this._SoTiepNhan;}
		}
		public DateTime NgayTiepNhan
		{
			set {this._NgayTiepNhan = value;}
			get {return this._NgayTiepNhan;}
		}
        public int TrangThai
		{
			set {this._TrangThai = value;}
			get {return this._TrangThai;}
		}
		public string MaHQ
		{
			set {this._MaHQ = value;}
            get { return this._MaHQ; }
		}
        public string CanBoDangKy
        {
            set { this._CanBoDangKy= value; }
            get { return this._CanBoDangKy; }
        }
        public DateTime NgayDangKy
        {
            set { this._NgayDangKy = value; }
            get { return this._NgayDangKy; }
        }
		public string MaNguoiNhan
		{
			set {this._MaNguoiNhan= value;}
            get { return this._MaNguoiNhan; }
		}
        public string TenNguoiNhan
        {
            set { this._TenNguoiNhan = value; }
            get { return this._TenNguoiNhan; }
        }
		public string SoHopDongNhan
		{
			set {this._SoHopDongNhan = value;}
			get {return this._SoHopDongNhan;}
		}
		public DateTime NgayHDNhan
		{
			set {this._NgayHDNhan= value;}
            get { return this._NgayHDNhan; }
		}
		public DateTime NgayHetHanHDNhan
		{
			set {this._NgayHetHanHDNhan= value;}
			get {return this._NgayHetHanHDNhan;}
		}
        public string MaNguoiGiao
        {
            set { this._MaNguoiGiao = value; }
            get { return this._MaNguoiGiao; }
        }
        public string TenNguoiGiao
        {
            set { this._TenNguoiGiao = value; }
            get { return this._TenNguoiGiao; }
        }
        public string SoHDGiao
        {
            set { this._SoHDGiao = value; }
            get { return this._SoHDGiao; }
        }
        public DateTime NgayHDGiao
        {
            set { this._NgayHDGiao = value; }
            get { return this._NgayHDGiao; }
        }
        public DateTime NgayHetHanHDGiao
        {
            set { this._NgayHetHanHDGiao = value; }
            get { return this._NgayHetHanHDGiao; }
        }
        public string NguoiChiDinhGiaoHang
        {
            set { this._NguoiChiDinhGiaoHang = value; }
            get { return this._NguoiChiDinhGiaoHang; }
        }
        public string MaDaiLy
        {
            set { this._MaDaiLy = value; }
            get { return this._MaDaiLy; }
        }
        public string TenDaiLy
        {
            set { this._TenDaiLy = value; }
            get { return this._TenDaiLy; }
        }
        public string MaLoaiHinh
        {
            set { this._MaLoaiHinh = value; }
            get { return this._MaLoaiHinh; }
        }
        public string TenLoaiHinh
        {
            set { this._TenLoaiHinh = value; }
            get { return this._TenLoaiHinh; }
        }
        public string DiaDiemXepHang
        {
            set { this._DiaDiemXepHang= value; }
            get { return this._DiaDiemXepHang; }
        }
        public decimal TyGiaVND
        {
            set { this._TyGiaVND= value; }
            get { return this._TyGiaVND; }
        }
        public decimal TyGiaUSD
        {
            set { this._TyGiaUSD = value; }
            get { return this._TyGiaUSD; }
        }
        public decimal LePhiHQ
        {
            set { this._LePhiHQ = value; }
            get { return this._LePhiHQ; }
        }
        public string SoBienLai
        {
            set { this._SoBienLai = value; }
            get { return this._SoBienLai; }
        }
        public DateTime NgayBienLai
        {
            set { this._NgayBienLai = value; }
            get { return this._NgayBienLai; }
        }
        public string ChungTu
        {
            set { this._ChungTu = value; }
            get { return this._ChungTu; }
        }
        public string MaNguyenTe
        {
            set { this._MaNguyenTe = value; }
            get { return this._MaNguyenTe; }
        }
		//---------------------------------------------------------------------------------------------
        
		public bool IsExist
        {
            get 
            { 
                return this.Load();  
            }
        }
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Select methods.
		
		public bool Load()
		{
			string spName = "p_KDT_GC_ToKhaiChuyenTiep_Load";
            SqlCommand dbCommand = (SqlCommand) this.db.GetStoredProcCommand(spName);
			
			this.db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, this._ID);
			
            IDataReader reader = this.db.ExecuteReader(dbCommand);
			if (reader.Read())
			{
				if (!reader.IsDBNull(reader.GetOrdinal("ID"))) this.ID = reader.GetInt64(reader.GetOrdinal("ID"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoTiepNhan"))) this.SoTiepNhan = reader.GetInt64(reader.GetOrdinal("SoTiepNhan"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayTiepNhan"))) this.NgayTiepNhan = reader.GetDateTime(reader.GetOrdinal("NgayTiepNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaHQ"))) this.MaHQ = reader.GetString(reader.GetOrdinal("MaHQ"));
                if (!reader.IsDBNull(reader.GetOrdinal("ToKhaiSo"))) this.ToKhaiSo = reader.GetInt32(reader.GetOrdinal("ToKhaiSo"));
                if (!reader.IsDBNull(reader.GetOrdinal("TrangThai"))) this.TrangThai = reader.GetInt32(reader.GetOrdinal("TrangThai"));
                if (!reader.IsDBNull(reader.GetOrdinal("CanBoDangKy"))) this.CanBoDangKy = reader.GetString(reader.GetOrdinal("CanBoDangKy"));         
                if (!reader.IsDBNull(reader.GetOrdinal("NgayDangKy"))) this.NgayDangKy = reader.GetDateTime(reader.GetOrdinal("NgayDangKy"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaNguoiNhan"))) this.MaNguoiNhan = reader.GetString(reader.GetOrdinal("MaNguoiNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenNguoiNhan"))) this.TenNguoiNhan = reader.GetString(reader.GetOrdinal("TenNguoiNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("SoHopDongNhan"))) this.SoHopDongNhan = reader.GetString(reader.GetOrdinal("SoHopDongNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHDNhan"))) this.NgayHDNhan = reader.GetDateTime(reader.GetOrdinal("NgayHDNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHetHanHDNhan"))) this.NgayHetHanHDNhan = reader.GetDateTime(reader.GetOrdinal("NgayHetHanHDNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaNguoiGiao"))) this.MaNguoiGiao = reader.GetString(reader.GetOrdinal("MaNguoiGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenNguoiGiao"))) this.TenNguoiGiao = reader.GetString(reader.GetOrdinal("TenNguoiGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("SoHDGiao"))) this.SoHDGiao = reader.GetString(reader.GetOrdinal("SoHDGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHDGiao"))) this.NgayHDGiao = reader.GetDateTime(reader.GetOrdinal("NgayHDGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHetHanHDGiao"))) this.NgayHetHanHDGiao = reader.GetDateTime(reader.GetOrdinal("NgayHetHanHDGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("NguoiChiDinhGiaoHang"))) this.NguoiChiDinhGiaoHang = reader.GetString(reader.GetOrdinal("NguoiChiDinhGiaoHang"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaDaiLy"))) this.MaDaiLy = reader.GetString(reader.GetOrdinal("MaDaiLy"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenDaiLy"))) this.TenDaiLy = reader.GetString(reader.GetOrdinal("TenDaiLy"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaLoaiHinh"))) this._MaLoaiHinh = reader.GetString(reader.GetOrdinal("MaLoaiHinh"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenLoaiHinh"))) this.TenLoaiHinh = reader.GetString(reader.GetOrdinal("TenLoaiHinh"));
                if (!reader.IsDBNull(reader.GetOrdinal("DiaDiemXepHang"))) this.DiaDiemXepHang = reader.GetString(reader.GetOrdinal("DiaDiemXepHang"));
                if (!reader.IsDBNull(reader.GetOrdinal("TyGiaVND"))) this.TyGiaVND = reader.GetDecimal(reader.GetOrdinal("TyGiaVND"));
                if (!reader.IsDBNull(reader.GetOrdinal("TyGiaUSD"))) this.TyGiaUSD = reader.GetDecimal(reader.GetOrdinal("TyGiaUSD"));
                if (!reader.IsDBNull(reader.GetOrdinal("LePhiHQ"))) this.LePhiHQ = reader.GetDecimal(reader.GetOrdinal("LePhiHQ"));
                if (!reader.IsDBNull(reader.GetOrdinal("SoBienLai"))) this.SoBienLai = reader.GetString(reader.GetOrdinal("SoBienLai"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayBienLai"))) this.NgayBienLai = reader.GetDateTime(reader.GetOrdinal("NgayBienLai"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChungTu"))) this.ChungTu = reader.GetString(reader.GetOrdinal("ChungTu"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaNguyenTe"))) this.MaNguyenTe = reader.GetString(reader.GetOrdinal("MaNguyenTe"));
                reader.Close();
				return true;
			}
			return false;
		}		
		
		//---------------------------------------------------------------------------------------------
		


		public DataSet SelectAll()
        {
            string spName = "p_KDT_GC_ToKhaiChuyenTiep_SelectAll";
            SqlCommand dbCommand = (SqlCommand) this.db.GetStoredProcCommand(spName);
            return this.db.ExecuteDataSet(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------

		public IDataReader SelectReaderAll()
        {
            string spName = "p_KDT_GC_ToKhaiChuyenTiep_SelectAll";
            SqlCommand dbCommand = (SqlCommand) this.db.GetStoredProcCommand(spName);
            return this.db.ExecuteReader(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public DataSet SelectDynamic(string whereCondition, string orderByExpression)
		{
            string spName = "p_KDT_GC_ToKhaiChuyenTiep_SelectDynamic";
            SqlCommand dbCommand = (SqlCommand) this.db.GetStoredProcCommand(spName);

			this.db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            this.db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return this.db.ExecuteDataSet(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------

		public IDataReader SelectReaderDynamic(string whereCondition, string orderByExpression)
		{
            string spName = "p_KDT_GC_ToKhaiChuyenTiep_SelectDynamic";
            SqlCommand dbCommand = (SqlCommand) this.db.GetStoredProcCommand(spName);

			this.db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            this.db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return this.db.ExecuteReader(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
		
		public ToKhaiChuyenTiepCollection SelectCollectionAll()
		{
			ToKhaiChuyenTiepCollection collection = new ToKhaiChuyenTiepCollection();

			IDataReader reader = this.SelectReaderAll();
			while (reader.Read())
			{
				ToKhaiChuyenTiep entity = new ToKhaiChuyenTiep();
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt64(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("SoTiepNhan"))) entity.SoTiepNhan = reader.GetInt64(reader.GetOrdinal("SoTiepNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayTiepNhan"))) entity.NgayTiepNhan = reader.GetDateTime(reader.GetOrdinal("NgayTiepNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaHQ"))) entity.MaHQ = reader.GetString(reader.GetOrdinal("MaHQ"));
                if (!reader.IsDBNull(reader.GetOrdinal("ToKhaiSo"))) entity.ToKhaiSo = reader.GetInt32(reader.GetOrdinal("ToKhaiSo"));
                if (!reader.IsDBNull(reader.GetOrdinal("TrangThai"))) entity.TrangThai = reader.GetInt32(reader.GetOrdinal("TrangThai"));
                if (!reader.IsDBNull(reader.GetOrdinal("CanBoDangKy"))) entity.CanBoDangKy = reader.GetString(reader.GetOrdinal("CanBoDangKy"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayDangKy"))) entity.NgayDangKy = reader.GetDateTime(reader.GetOrdinal("NgayDangKy"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaNguoiNhan"))) entity.MaNguoiNhan = reader.GetString(reader.GetOrdinal("MaNguoiNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenNguoiNhan"))) entity.TenNguoiNhan = reader.GetString(reader.GetOrdinal("TenNguoiNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("SoHopDongNhan"))) entity.SoHopDongNhan = reader.GetString(reader.GetOrdinal("SoHopDongNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHDNhan"))) entity.NgayHDNhan = reader.GetDateTime(reader.GetOrdinal("NgayHDNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHetHanHDNhan"))) entity.NgayHetHanHDNhan = reader.GetDateTime(reader.GetOrdinal("NgayHetHanHDNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaNguoiGiao"))) entity.MaNguoiGiao = reader.GetString(reader.GetOrdinal("MaNguoiGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenNguoiGiao"))) entity.TenNguoiGiao = reader.GetString(reader.GetOrdinal("TenNguoiGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("SoHDGiao"))) entity.SoHDGiao = reader.GetString(reader.GetOrdinal("SoHDGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHDGiao"))) entity.NgayHDGiao = reader.GetDateTime(reader.GetOrdinal("NgayHDGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHetHanHDGiao"))) entity.NgayHetHanHDGiao = reader.GetDateTime(reader.GetOrdinal("NgayHetHanHDGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("NguoiChiDinhGiaoHang"))) entity.NguoiChiDinhGiaoHang = reader.GetString(reader.GetOrdinal("NguoiChiDinhGiaoHang"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaDaiLy"))) entity.MaDaiLy = reader.GetString(reader.GetOrdinal("MaDaiLy"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenDaiLy"))) entity.TenDaiLy = reader.GetString(reader.GetOrdinal("TenDaiLy"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaLoaiHinh"))) entity._MaLoaiHinh = reader.GetString(reader.GetOrdinal("MaLoaiHinh"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenLoaiHinh"))) entity.TenLoaiHinh = reader.GetString(reader.GetOrdinal("TenLoaiHinh"));
                if (!reader.IsDBNull(reader.GetOrdinal("DiaDiemXepHang"))) entity.DiaDiemXepHang = reader.GetString(reader.GetOrdinal("DiaDiemXepHang"));
                if (!reader.IsDBNull(reader.GetOrdinal("TyGiaVND"))) entity.TyGiaVND = reader.GetDecimal(reader.GetOrdinal("TyGiaVND"));
                if (!reader.IsDBNull(reader.GetOrdinal("TyGiaUSD"))) entity.TyGiaUSD = reader.GetDecimal(reader.GetOrdinal("TyGiaUSD"));
                if (!reader.IsDBNull(reader.GetOrdinal("LePhiHQ"))) entity.LePhiHQ = reader.GetDecimal(reader.GetOrdinal("LePhiHQ"));
                if (!reader.IsDBNull(reader.GetOrdinal("SoBienLai"))) entity.SoBienLai = reader.GetString(reader.GetOrdinal("SoBienLai"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayBienLai"))) entity.NgayBienLai = reader.GetDateTime(reader.GetOrdinal("NgayBienLai"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChungTu"))) entity.ChungTu = reader.GetString(reader.GetOrdinal("ChungTu")); collection.Add(entity);
                if (!reader.IsDBNull(reader.GetOrdinal("MaNguyenTe"))) entity.MaNguyenTe = reader.GetString(reader.GetOrdinal("MaNguyenTe")); collection.Add(entity);

			}
            reader.Close();
			return collection;			
		}
		
		//---------------------------------------------------------------------------------------------
		
		public ToKhaiChuyenTiepCollection SelectCollectionDynamic(string whereCondition, string orderByExpression)
		{
			ToKhaiChuyenTiepCollection collection = new ToKhaiChuyenTiepCollection();

			IDataReader reader = this.SelectReaderDynamic(whereCondition, orderByExpression);
			while (reader.Read())
			{
				ToKhaiChuyenTiep entity = new ToKhaiChuyenTiep();
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt64(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("SoTiepNhan"))) entity.SoTiepNhan = reader.GetInt64(reader.GetOrdinal("SoTiepNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayTiepNhan"))) entity.NgayTiepNhan = reader.GetDateTime(reader.GetOrdinal("NgayTiepNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaHQ"))) entity.MaHQ = reader.GetString(reader.GetOrdinal("MaHQ"));
                if (!reader.IsDBNull(reader.GetOrdinal("ToKhaiSo"))) entity.ToKhaiSo = reader.GetInt32(reader.GetOrdinal("ToKhaiSo"));
                if (!reader.IsDBNull(reader.GetOrdinal("TrangThai"))) entity.TrangThai = reader.GetInt32(reader.GetOrdinal("TrangThai"));
                if (!reader.IsDBNull(reader.GetOrdinal("CanBoDangKy"))) entity.CanBoDangKy = reader.GetString(reader.GetOrdinal("CanBoDangKy"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayDangKy"))) entity.NgayDangKy = reader.GetDateTime(reader.GetOrdinal("NgayDangKy"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaNguoiNhan"))) entity.MaNguoiNhan = reader.GetString(reader.GetOrdinal("MaNguoiNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenNguoiNhan"))) entity.TenNguoiNhan = reader.GetString(reader.GetOrdinal("TenNguoiNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("SoHopDongNhan"))) entity.SoHopDongNhan = reader.GetString(reader.GetOrdinal("SoHopDongNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHDNhan"))) entity.NgayHDNhan = reader.GetDateTime(reader.GetOrdinal("NgayHDNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHetHanHDNhan"))) entity.NgayHetHanHDNhan = reader.GetDateTime(reader.GetOrdinal("NgayHetHanHDNhan"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaNguoiGiao"))) entity.MaNguoiGiao = reader.GetString(reader.GetOrdinal("MaNguoiGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenNguoiGiao"))) entity.TenNguoiGiao = reader.GetString(reader.GetOrdinal("TenNguoiGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("SoHDGiao"))) entity.SoHDGiao = reader.GetString(reader.GetOrdinal("SoHDGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHDGiao"))) entity.NgayHDGiao = reader.GetDateTime(reader.GetOrdinal("NgayHDGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayHetHanHDGiao"))) entity.NgayHetHanHDGiao = reader.GetDateTime(reader.GetOrdinal("NgayHetHanHDGiao"));
                if (!reader.IsDBNull(reader.GetOrdinal("NguoiChiDinhGiaoHang"))) entity.NguoiChiDinhGiaoHang = reader.GetString(reader.GetOrdinal("NguoiChiDinhGiaoHang"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaDaiLy"))) entity.MaDaiLy = reader.GetString(reader.GetOrdinal("MaDaiLy"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenDaiLy"))) entity.TenDaiLy = reader.GetString(reader.GetOrdinal("TenDaiLy"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaLoaiHinh"))) entity._MaLoaiHinh = reader.GetString(reader.GetOrdinal("MaLoaiHinh"));
                if (!reader.IsDBNull(reader.GetOrdinal("TenLoaiHinh"))) entity.TenLoaiHinh = reader.GetString(reader.GetOrdinal("TenLoaiHinh"));
                if (!reader.IsDBNull(reader.GetOrdinal("DiaDiemXepHang"))) entity.DiaDiemXepHang = reader.GetString(reader.GetOrdinal("DiaDiemXepHang"));
                if (!reader.IsDBNull(reader.GetOrdinal("TyGiaVND"))) entity.TyGiaVND = reader.GetDecimal(reader.GetOrdinal("TyGiaVND"));
                if (!reader.IsDBNull(reader.GetOrdinal("TyGiaUSD"))) entity.TyGiaUSD = reader.GetDecimal(reader.GetOrdinal("TyGiaUSD"));
                if (!reader.IsDBNull(reader.GetOrdinal("LePhiHQ"))) entity.LePhiHQ = reader.GetDecimal(reader.GetOrdinal("LePhiHQ"));
                if (!reader.IsDBNull(reader.GetOrdinal("SoBienLai"))) entity.SoBienLai = reader.GetString(reader.GetOrdinal("SoBienLai"));
                if (!reader.IsDBNull(reader.GetOrdinal("NgayBienLai"))) entity.NgayBienLai = reader.GetDateTime(reader.GetOrdinal("NgayBienLai"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChungTu"))) entity.ChungTu = reader.GetString(reader.GetOrdinal("ChungTu"));
                if (!reader.IsDBNull(reader.GetOrdinal("MaNguyenTe"))) entity.MaNguyenTe = reader.GetString(reader.GetOrdinal("MaNguyenTe"));

				collection.Add(entity);
			}
            reader.Close();
			return collection;			
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert methods.
		
		public long Insert()
		{
			return this.InsertTransaction(null);
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public long InsertTransaction(SqlTransaction transaction)
		{			
			string spName = "p_KDT_GC_ToKhaiChuyenTiep_Insert";		
			SqlCommand dbCommand = (SqlCommand) this.db.GetStoredProcCommand(spName);
			this.db.AddOutParameter(dbCommand, "@ID", SqlDbType.BigInt, 8);
			this.db.AddInParameter(dbCommand, "@SoTiepNhan", SqlDbType.BigInt, this.SoTiepNhan);
			this.db.AddInParameter(dbCommand, "@NgayTiepNhan", SqlDbType.DateTime, this.NgayTiepNhan);
            this.db.AddInParameter(dbCommand, "@TrangThai", SqlDbType.Int, this.TrangThai);
            this.db.AddInParameter(dbCommand, "@MaHQ", SqlDbType.Char, this.MaHQ);
            this.db.AddInParameter(dbCommand, "@ToKhaiSo", SqlDbType.Int, this.ToKhaiSo);
            this.db.AddInParameter(dbCommand, "@CanBoDangKy", SqlDbType.NVarChar, this.CanBoDangKy);
            this.db.AddInParameter(dbCommand, "@NgayDangKy", SqlDbType.DateTime, this.NgayDangKy);
            this.db.AddInParameter(dbCommand, "@MaNguoiNhan", SqlDbType.VarChar, this.MaNguoiNhan);
            this.db.AddInParameter(dbCommand, "@TenNguoiNhan", SqlDbType.NVarChar, this.TenNguoiNhan);
            this.db.AddInParameter(dbCommand, "@SoHopDongNhan", SqlDbType.VarChar, this.SoHopDongNhan);
            this.db.AddInParameter(dbCommand, "@NgayHDNhan", SqlDbType.DateTime, this.NgayHDNhan);
            this.db.AddInParameter(dbCommand, "@NgayHetHanHDNhan", SqlDbType.DateTime, this.NgayHetHanHDNhan);
            this.db.AddInParameter(dbCommand, "@MaNguoiGiao", SqlDbType.VarChar, this.MaNguoiGiao);
            this.db.AddInParameter(dbCommand, "@TenNguoiGiao", SqlDbType.NVarChar, this.TenNguoiGiao);
            this.db.AddInParameter(dbCommand, "@SoHDGiao", SqlDbType.VarChar, this.SoHDGiao);
            this.db.AddInParameter(dbCommand, "@NgayHDGiao", SqlDbType.DateTime, this.NgayHDGiao);
            this.db.AddInParameter(dbCommand, "@NgayHetHanHDGiao", SqlDbType.DateTime, this.NgayHetHanHDGiao);
            this.db.AddInParameter(dbCommand, "@NguoiChiDinhGiaoHang", SqlDbType.NVarChar, this.NguoiChiDinhGiaoHang);
            this.db.AddInParameter(dbCommand, "@MaDaiLy", SqlDbType.VarChar, this.MaDaiLy);
            this.db.AddInParameter(dbCommand, "@TenDaiLy", SqlDbType.NVarChar, this.TenDaiLy);
            this.db.AddInParameter(dbCommand, "@MaLoaiHinh", SqlDbType.VarChar, this.MaLoaiHinh);
            this.db.AddInParameter(dbCommand, "@TenLoaiHinh", SqlDbType.NVarChar, this.TenLoaiHinh);
            this.db.AddInParameter(dbCommand, "@DiaDiemXepHang", SqlDbType.NVarChar, this.DiaDiemXepHang);
            this.db.AddInParameter(dbCommand, "@TyGiaVND", SqlDbType.Money, this.TyGiaVND);
            this.db.AddInParameter(dbCommand, "@TyGiaUSD", SqlDbType.Money, this.TyGiaUSD);
            this.db.AddInParameter(dbCommand, "@LePhiHQ", SqlDbType.Money, this.LePhiHQ);
            this.db.AddInParameter(dbCommand, "@SoBienLai", SqlDbType.NChar, this.SoBienLai);
            this.db.AddInParameter(dbCommand, "@NgayBienLai", SqlDbType.DateTime, this.NgayBienLai);
            this.db.AddInParameter(dbCommand, "@ChungTu", SqlDbType.NVarChar, this.ChungTu);
            this.db.AddInParameter(dbCommand, "@MaNguyenTe", SqlDbType.Char, this.MaNguyenTe);
            if (transaction != null)
			{
				this.db.ExecuteNonQuery(dbCommand, transaction);
				this._ID = (long) this.db.GetParameterValue(dbCommand, "@ID");
				return this._ID;
			}
            else
			{
				this.db.ExecuteNonQuery(dbCommand);
				this._ID = (long) this.db.GetParameterValue(dbCommand, "@ID");
				return this._ID;
			}			
		}
		
		//---------------------------------------------------------------------------------------------
		
		public bool Insert(ToKhaiChuyenTiepCollection collection)
        {
            bool ret;
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                SqlTransaction transaction = connection.BeginTransaction();
                try
                {
					bool ret01 = true;
                    foreach (ToKhaiChuyenTiep item in collection)
                    {
                        if (item.InsertTransaction(transaction) <= 0)
						{							
							ret01 = false;
							break;
						}
                    }
					if (ret01)
					{
                    	transaction.Commit();
                    	ret = true;
					}
					else
					{
                    	transaction.Rollback();
						ret = false;                    	
					}
                }
                catch
                {
                    ret = false;
                    transaction.Rollback();
                }
                finally 
                {
                    connection.Close();
                }
            }
            return ret;		
		}
		
		//---------------------------------------------------------------------------------------------		
        
		public void InsertTransaction(SqlTransaction transaction, ToKhaiChuyenTiepCollection collection)
        {
            foreach (ToKhaiChuyenTiep item in collection)
            {
               	item.InsertTransaction(transaction);
            }
        }
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert / Update methods.
		public int InsertUpdate()
		{
			return this.InsertUpdateTransaction(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int InsertUpdateTransaction(SqlTransaction transaction)
		{			
			string spName = "p_KDTGC__ToKhaiChuyenTiep_InsertUpdate";		
			SqlCommand dbCommand = (SqlCommand) this.db.GetStoredProcCommand(spName);
            this.db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, this.ID);
            this.db.AddInParameter(dbCommand, "@SoTiepNhan", SqlDbType.BigInt, this.SoTiepNhan);
            this.db.AddInParameter(dbCommand, "@NgayTiepNhan", SqlDbType.DateTime, this.NgayTiepNhan);
            this.db.AddInParameter(dbCommand, "@TrangThai", SqlDbType.Int, this.TrangThai);
            this.db.AddInParameter(dbCommand, "@MaHQ", SqlDbType.Char, this.MaHQ);
            this.db.AddInParameter(dbCommand, "@ToKhaiSo", SqlDbType.Int, this.ToKhaiSo);
            this.db.AddInParameter(dbCommand, "@CanBoDangKy", SqlDbType.NVarChar, this.CanBoDangKy);
            this.db.AddInParameter(dbCommand, "@NgayDangKy", SqlDbType.DateTime, this.NgayDangKy);
            this.db.AddInParameter(dbCommand, "@MaNguoiNhan", SqlDbType.VarChar, this.MaNguoiNhan);
            this.db.AddInParameter(dbCommand, "@TenNguoiNhan", SqlDbType.NVarChar, this.TenNguoiNhan);
            this.db.AddInParameter(dbCommand, "@SoHopDongNhan", SqlDbType.VarChar, this.SoHopDongNhan);
            this.db.AddInParameter(dbCommand, "@NgayHDNhan", SqlDbType.DateTime, this.NgayHDNhan);
            this.db.AddInParameter(dbCommand, "@NgayHetHanHDNhan", SqlDbType.DateTime, this.NgayHetHanHDNhan);
            this.db.AddInParameter(dbCommand, "@MaNguoiGiao", SqlDbType.VarChar, this.MaNguoiGiao);
            this.db.AddInParameter(dbCommand, "@TenNguoiGiao", SqlDbType.NVarChar, this.TenNguoiGiao);
            this.db.AddInParameter(dbCommand, "@SoHDGiao", SqlDbType.VarChar, this.SoHDGiao);
            this.db.AddInParameter(dbCommand, "@NgayHDGiao", SqlDbType.DateTime, this.NgayHDGiao);
            this.db.AddInParameter(dbCommand, "@NgayHetHanHDGiao", SqlDbType.DateTime, this.NgayHetHanHDGiao);
            this.db.AddInParameter(dbCommand, "@NguoiChiDinhGiaoHang", SqlDbType.NVarChar, this.NguoiChiDinhGiaoHang);
            this.db.AddInParameter(dbCommand, "@MaDaiLy", SqlDbType.VarChar, this.MaDaiLy);
            this.db.AddInParameter(dbCommand, "@TenDaiLy", SqlDbType.NVarChar, this.TenDaiLy);
            this.db.AddInParameter(dbCommand, "@MaLoaiHinh", SqlDbType.VarChar, this.MaLoaiHinh);
            this.db.AddInParameter(dbCommand, "@TenLoaiHinh", SqlDbType.NVarChar, this.TenLoaiHinh);
            this.db.AddInParameter(dbCommand, "@DiaDiemXepHang", SqlDbType.NVarChar, this.DiaDiemXepHang);
            this.db.AddInParameter(dbCommand, "@TyGiaVND", SqlDbType.Money, this.TyGiaVND);
            this.db.AddInParameter(dbCommand, "@TyGiaUSD", SqlDbType.Money, this.TyGiaUSD);
            this.db.AddInParameter(dbCommand, "@LePhiHQ", SqlDbType.Money, this.LePhiHQ);
            this.db.AddInParameter(dbCommand, "@SoBienLai", SqlDbType.NChar, this.SoBienLai);
            this.db.AddInParameter(dbCommand, "@NgayBienLai", SqlDbType.DateTime, this.NgayBienLai);
            this.db.AddInParameter(dbCommand, "@ChungTu", SqlDbType.NVarChar, this.ChungTu);
            this.db.AddInParameter(dbCommand, "@MaNguyenTe", SqlDbType.Char, this.MaNguyenTe);

			if (transaction != null)
                return this.db.ExecuteNonQuery(dbCommand, transaction);
            else
                return this.db.ExecuteNonQuery(dbCommand);			
		}
		
		//---------------------------------------------------------------------------------------------
		
		public bool InsertUpdate(ToKhaiChuyenTiepCollection collection)
        {
            bool ret;
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                SqlTransaction transaction = connection.BeginTransaction();
                try
                {
					bool ret01 = true;
                    foreach (ToKhaiChuyenTiep item in collection)
                    {
                        if (item.InsertUpdateTransaction(transaction) <= 0)
						{
							ret01 = false;
							break;
						}
                    }
					if (ret01)
					{
						transaction.Commit();
						ret = true;
					}
					else
					{
						transaction.Rollback();
						ret = false;                    	
					}
                }
                catch
                {
                    ret = false;
                    transaction.Rollback();
                }
                finally 
                {
                    connection.Close();
                }
            }
            return ret;		
		}		
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Update methods.
		
		public int Update()
		{
			return this.UpdateTransaction(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int UpdateTransaction(SqlTransaction transaction)
		{
			string spName = "p_KDT_GC_ToKhaiChuyenTiep_Update";		
			SqlCommand dbCommand = (SqlCommand) this.db.GetStoredProcCommand(spName);

            this.db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, this.ID);
            this.db.AddInParameter(dbCommand, "@SoTiepNhan", SqlDbType.BigInt, this.SoTiepNhan);
            this.db.AddInParameter(dbCommand, "@NgayTiepNhan", SqlDbType.DateTime, this.NgayTiepNhan);
            this.db.AddInParameter(dbCommand, "@TrangThai", SqlDbType.Int, this.TrangThai);
            this.db.AddInParameter(dbCommand, "@MaHQ", SqlDbType.Char, this.MaHQ);
            this.db.AddInParameter(dbCommand, "@ToKhaiSo", SqlDbType.Int, this.ToKhaiSo);
            this.db.AddInParameter(dbCommand, "@CanBoDangKy", SqlDbType.NVarChar, this.CanBoDangKy);
            this.db.AddInParameter(dbCommand, "@NgayDangKy", SqlDbType.DateTime, this.NgayDangKy);
            this.db.AddInParameter(dbCommand, "@MaNguoiNhan", SqlDbType.VarChar, this.MaNguoiNhan);
            this.db.AddInParameter(dbCommand, "@TenNguoiNhan", SqlDbType.NVarChar, this.TenNguoiNhan);
            this.db.AddInParameter(dbCommand, "@SoHopDongNhan", SqlDbType.VarChar, this.SoHopDongNhan);
            this.db.AddInParameter(dbCommand, "@NgayHDNhan", SqlDbType.DateTime, this.NgayHDNhan);
            this.db.AddInParameter(dbCommand, "@NgayHetHanHDNhan", SqlDbType.DateTime, this.NgayHetHanHDNhan);
            this.db.AddInParameter(dbCommand, "@MaNguoiGiao", SqlDbType.VarChar, this.MaNguoiGiao);
            this.db.AddInParameter(dbCommand, "@TenNguoiGiao", SqlDbType.NVarChar, this.TenNguoiGiao);
            this.db.AddInParameter(dbCommand, "@SoHDGiao", SqlDbType.VarChar, this.SoHDGiao);
            this.db.AddInParameter(dbCommand, "@NgayHDGiao", SqlDbType.DateTime, this.NgayHDGiao);
            this.db.AddInParameter(dbCommand, "@NgayHetHanHDGiao", SqlDbType.DateTime, this.NgayHetHanHDGiao);
            this.db.AddInParameter(dbCommand, "@NguoiChiDinhGiaoHang", SqlDbType.NVarChar, this.NguoiChiDinhGiaoHang);
            this.db.AddInParameter(dbCommand, "@MaDaiLy", SqlDbType.VarChar, this.MaDaiLy);
            this.db.AddInParameter(dbCommand, "@TenDaiLy", SqlDbType.NVarChar, this.TenDaiLy);
            this.db.AddInParameter(dbCommand, "@MaLoaiHinh", SqlDbType.VarChar, this.MaLoaiHinh);
            this.db.AddInParameter(dbCommand, "@TenLoaiHinh", SqlDbType.NVarChar, this.TenLoaiHinh);
            this.db.AddInParameter(dbCommand, "@DiaDiemXepHang", SqlDbType.NVarChar, this.DiaDiemXepHang);
            this.db.AddInParameter(dbCommand, "@TyGiaVND", SqlDbType.Money, this.TyGiaVND);
            this.db.AddInParameter(dbCommand, "@TyGiaUSD", SqlDbType.Money, this.TyGiaUSD);
            this.db.AddInParameter(dbCommand, "@LePhiHQ", SqlDbType.Money, this.LePhiHQ);
            this.db.AddInParameter(dbCommand, "@SoBienLai", SqlDbType.NChar, this.SoBienLai);
            this.db.AddInParameter(dbCommand, "@NgayBienLai", SqlDbType.DateTime, this.NgayBienLai);
            this.db.AddInParameter(dbCommand, "@ChungTu", SqlDbType.NVarChar, this.ChungTu);
            this.db.AddInParameter(dbCommand, "@MaNguyenTe", SqlDbType.Char, this.MaNguyenTe);

			if (transaction != null)
                return this.db.ExecuteNonQuery(dbCommand, transaction);
            else
                return this.db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
		
		public void UpdateCollection(ToKhaiChuyenTiepCollection collection, SqlTransaction transaction)
        {
            foreach (ToKhaiChuyenTiep item in collection)
            {
                item.UpdateTransaction(transaction);
            }
        }

		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Delete methods.
		
		public int Delete()
		{
			return this.DeleteTransaction(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int DeleteTransaction(SqlTransaction transaction)
		{
			string spName = "p_KDT_GC_ToKhaiChuyenTiep_Delete";		
			SqlCommand dbCommand = (SqlCommand) this.db.GetStoredProcCommand(spName);
			
			this.db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, this._ID);
			
			if (transaction != null)
                return this.db.ExecuteNonQuery(dbCommand, transaction);
            else
                return this.db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
		
        public void DeleteCollection(ToKhaiChuyenTiepCollection collection, SqlTransaction transaction)
        {
            foreach (ToKhaiChuyenTiep item in collection)
            {
                item.DeleteTransaction(transaction);
            }
        }

		//---------------------------------------------------------------------------------------------
		
		public bool DeleteCollection(ToKhaiChuyenTiepCollection collection)
        {
            bool ret;
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                SqlTransaction transaction = connection.BeginTransaction();
                try
                {
					bool ret01 = true;
                    foreach (ToKhaiChuyenTiep item in collection)
                    {
                        if (item.DeleteTransaction(transaction) <= 0)
						{
							ret01 = false;
							break;
						}
                    }
					if (ret01)
					{
						transaction.Commit();
						ret = true;
					}
					else
					{
						transaction.Rollback();
						ret = false;                    	
					}
                }
                catch
                {
                    ret = false;
                    transaction.Rollback();
                }
                finally 
                {
                    connection.Close();
                }
            }
            return ret;		
		}
		#endregion
	}	
}